#ifndef MONITOR_CFG_MANAGER_H_
#define MONITOR_CFG_MANAGER_H_
#include <gtkmm/comboboxtext.h>
class CfgManager: public Gtk::Window {
private:
	Gtk::VBox v_box;
	Gtk::HBox h_box;
	Gtk::Entry port_entry, storage_entry;
	Gtk::Label label_port, label_storage;
	Gtk::Button accept_button, cancel_button;
	Monitor* m;
public:
	CfgManager(Monitor* m) :
			label_storage("Enter storage path"), label_port(
					"Enter connection port"), accept_button("Accept"), cancel_button(
					"Cancel") {
		this->m = m;
		set_modal(true);
		set_size_request(300, 200);
		set_title("Configuration manager");
		accept_button.signal_clicked().connect(
				sigc::mem_fun(*this, &CfgManager::on_accept_clicked));
		cancel_button.signal_clicked().connect(
				sigc::mem_fun(*this, &CfgManager::on_cancel_clicked));
		add(v_box);
		v_box.pack_start(label_port);
		v_box.pack_start(port_entry);
		port_entry.set_max_length(5);
		port_entry.set_text(m->GetPort());
		v_box.pack_start(label_storage);
		v_box.pack_start(storage_entry);
		storage_entry.set_max_length(150);
		storage_entry.set_text(m->GetStorage());
		v_box.pack_start(h_box);
		h_box.pack_start(accept_button);
		h_box.pack_start(cancel_button);
		show_all_children();
	}

	void on_accept_clicked() {
		string port = port_entry.get_text();
		string storage = storage_entry.get_text();
		int port_edit_result, storage_edit_result;
		string result = "Configuration was modified";
		port_edit_result = m->ChangePort(&port);
		storage_edit_result = m->ChangeStoragePath(&storage);
		if (!((port_edit_result) && (storage_edit_result))) {
			result = "Invalid new parameter(s). Configuration not modified";
		}
		Gtk::MessageDialog dialog(*this, result);
		dialog.run();
		Gtk::Main::quit();
	}
	void on_cancel_clicked() {
		Gtk::Main::quit();
	}
};

#endif /* MONITOR_CFG_MANAGER_H_ */
